package com.resou.reader.paycenter.v;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.resou.reader.utils.log.DLog;

/**
 * Created by ${Garrett} on 2018/10/16.
 * Contact me krouky@outlook.com
 */
public class PayConfigItemDecoration extends RecyclerView.ItemDecoration {

    private Paint mPaint;

    public PayConfigItemDecoration() {
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setColor(0xfff4f4f4);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(2);
    }

    @Override
    public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
    }

    @Override
    public void onDrawOver(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
        super.onDrawOver(c, parent, state);
        int childCount = parent.getChildCount();
        for (int i = 0; i < childCount; i++) {
            View child = parent.getChildAt(i);
            if (i % 2 == 0) {
                c.drawLine(child.getRight(), child.getTop(), child.getRight(), child.getBottom(), mPaint);
            }
            if (i >= 2) {
                c.drawLine(child.getLeft(), child.getTop(), child.getRight(), child.getTop(), mPaint);
            }
        }
    }
}
